package com.hq.modules.operate.controller;

import com.hq.common.annotation.SysLog;
import com.hq.common.utils.R;
import com.hq.modules.sys.controller.AbstractController;
import com.hq.modules.sys.dao.GridOperatorMapper;
import com.hq.modules.sys.dao.PeopleMapper;
import com.hq.modules.sys.dao.TypeMapper;
import com.hq.modules.sys.entity.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * 人员信息
 */
@RestController
@RequestMapping("/people")
public class PeopleInfoController extends AbstractController {

    @Resource
    private PeopleMapper peopleMapper;
    @Resource
    private GridOperatorMapper gridOperatorMapper;

    @Resource
    private TypeMapper typeMapper;


    /**
     * 新增人员信息
     */
    @SysLog("新增人员信息")
    @PostMapping("/savePeople")
    public People savePeople(@RequestBody People people) {
        peopleMapper.insertSelective(people);
        people.setId(people.getId());
        return people;
    }

    /**
     * 修改人员信息
     */
    @SysLog("修改人员信息")
    @PostMapping("/alertPeople")
    public R alertPeople(@RequestBody People people) {
        peopleMapper.updateByPrimaryKeySelective(people);
        return R.ok();
    }

    /**
     * 移除人员信息
     */
    @SysLog("移除人员信息")
    @PostMapping("/removePeople")
    public R removePeople(@RequestBody People people) {
        peopleMapper.deleteByPrimaryKey(people.getId());
        return R.ok();
    }
    /**
     * 查询某栋楼里的人口信息
     */
    @SysLog("查询某栋楼信息")
    @PostMapping("/selectAll")
    public List<People> selectAll(@RequestBody People people) {
        List<People> peoples = peopleMapper.selectByAll(people);
        return peoples;
    }
    /**
     * 查询某栋楼里的人口信息
     */
    @SysLog("查询某栋楼信息")
    @PostMapping("/selectAllPeopleByBuildingId")
    public List<People> selectAllPeople(@RequestBody People people) {
        List<People> peoples = peopleMapper.selectAllByBuildingId(people.getBuildingId());
        return peoples;
    }
    /**
     * 查询某栋楼信息
     */
    @SysLog("查询某人信息")
    @PostMapping("/selectAllPeopleById")
    public People selectAllPeopleById(@RequestBody People people) {
        People info = peopleMapper.selectByPrimaryKey(people.getId());
        return info;
    }
    /**
     * 人员统计
     */
    @SysLog("人员统计")
    @PostMapping("/personnelStatistics")
    public List<StatisticsResult> personnelStatistics(@RequestBody Statistics personnelStatistics) {
        List<StatisticsResult> statisticsResult = peopleMapper.personnelStatistics(personnelStatistics.getId());
        return statisticsResult;
    }

    /**
     * 房屋统计
     */
    @SysLog("房屋统计")
    @PostMapping("/buildingStatistics")
    public List<StatisticsResult> buildingStatistics(@RequestBody Statistics personnelStatistics) {
        List<StatisticsResult> statisticsResult = peopleMapper.buildingInfoStatistics(personnelStatistics.getId());
        return statisticsResult;
    }


    /**
     * 类型检索
     */
    @SysLog("类型检索")
    @PostMapping("/selectType")
    public List<Type> selectType(@RequestBody Type type) {
        List<Type> types = typeMapper.selectByType(type.getType());
        return types;
    }




    /**
     * 新增网格员信息
     */
    @SysLog("新增网格员信息")
    @PostMapping("/saveGridOperator")
    public People savegridOperator(@RequestBody People people) {
        peopleMapper.insertSelective(people);
        people.setId(people.getId());
        return people;
    }

//    /**
//     * 修改人员信息
//     */
//    @SysLog("修改人员信息")
//    @PostMapping("/alertGridOperator")
//    public R alertPeople(@RequestBody People people) {
//        peopleMapper.updateByPrimaryKeySelective(people);
//        return R.ok();
//    }
//
//    /**
//     * 移除人员信息
//     */
//    @SysLog("移除人员信息")
//    @PostMapping("/removeGridOperator")
//    public R removePeople(@RequestBody People people) {
//        peopleMapper.deleteByPrimaryKey(people.getId());
//        return R.ok();
//    }
//
//    /**
//     * 查询某栋楼里的人口信息
//     */
//    @SysLog("查询某栋楼信息")
//    @PostMapping("/selectAllGridOperatorByBuildingId")
//    public List<People> selectAllPeople(@RequestBody People people) {
//        List<People> peoples = peopleMapper.selectAllByBuildingId(people.getBuildingId());
//        return peoples;
//    }
//    /**
//     * 查询某栋楼信息
//     */
//    @SysLog("查询某人信息")
//    @PostMapping("/selectAllGridOperatorById")
//    public People selectAllPeopleById(@RequestBody People people) {
//        People info = peopleMapper.selectByPrimaryKey(people.getId());
//        return people;
//    }

}
